import re

text = """
{
    'name': 'Tom',
    'age': 20,
}
[phone](13755556666)
"""

# 1.匹配 name
pattern_name = r"'name': '(\w+)',"
# 2.匹配 age
pattern_age = r"'age': (\d+),"
# 3.匹配 phone
pattern_address = r"\[(\w+)\]\((\d+)\)"

# 4.sub 替换
new_name = "Jerry"
new_age = 25
new_phone = "13888889999"
text = re.sub(pattern_name, rf"'name': '{new_name}'", text)
text = re.sub(pattern_age, rf"'age': '{new_age}'", text)
text = re.sub(pattern_address, rf"[phone]({new_phone})", text)
print(text)
'''
{
    'name': 'Jerry'
    'age': 25
}
[phone](13888889999)
'''